package io.wit.modules.sys.service.impl;

import io.wit.modules.sys.dao.SysUserRoleDao;
import io.wit.modules.sys.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户与角色对应关系
*/
@Service("sysUserRoleService")
public class SysUserRoleServiceImpl implements SysUserRoleService {

    @Autowired
	private SysUserRoleDao sysUserRoleDao;

	@Override
	public int saveOrUpdate(final Long userId,final Long roleId) {
		//先删除用户与角色关系
		sysUserRoleDao.delete(userId);
		//保存用户与角色关系
		final Map<String, Object> map = new HashMap<>();
		map.put("userId", userId);
		map.put("roleId", roleId);
		return sysUserRoleDao.save(map);
	}

	@Override
	public List<Long> queryRoleIdList(Long userId) {
		return sysUserRoleDao.queryRoleIdList(userId);
	}

	@Override
	public void delete(Long userId) {
		sysUserRoleDao.delete(userId);
	}
}
